//
//  XUTabBarController.m
//  新浪微博
//
//  Created by xuwenxin on 15-4-8.
//  Copyright (c) 2015年 xuwenxin. All rights reserved.
//

#import "XUTabBarController.h"
#import "UIView+Frame.h"
#import "XUFirstController.h"
#import "XUTabBar.h"

@interface XUTabBarController () <UITabBarControllerDelegate,XUTabBarDelegate>
@property (weak, nonatomic) IBOutlet XUTabBar *xuTabbarbutton;

@end

@implementation XUTabBarController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
//    self.xuTabbarbutton.XUdelegate = self;
    
    __weak typeof(self) weakSelf = self;
    self.xuTabbarbutton.myBlock = ^{
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"XUSend" bundle:nil];
        UINavigationController *nav = sb.instantiateInitialViewController;
        
        [weakSelf presentViewController:nav animated:YES completion:nil];
    };
    
    [self addController];
}
- (void)XUTabBarDelegateWithdelegate
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"XUSend" bundle:nil];
    UINavigationController *nav = sb.instantiateInitialViewController;
    
    [self presentViewController:nav animated:YES completion:nil];
}

// 添加控制器
- (void)addController
{
    // 首页
    [self addChildStoryboardName:@"First" title:@"首页" imageName:@"tabbar_home" selectedImageName:@"tabbar_home_selected"];
    
    // 消息
    [self addChildStoryboardName:@"Messege" title:@"消息" imageName:@"tabbar_message_center" selectedImageName:@"tabbar_message_center_selected"];
    // 发现
    [self addChildStoryboardName:@"Find" title:@"发现" imageName:@"tabbar_discover" selectedImageName:@"tabbar_discover_selected"];
    // 我的
    [self addChildStoryboardName:@"My" title:@"我的" imageName:@"tabbar_profile" selectedImageName:@"tabbar_profile_selected"];
}

// 利用storyboard添加控制器
- (void)addChildStoryboardName:(NSString *)sbName title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:sbName bundle:nil];
    UINavigationController *vc = sb.instantiateInitialViewController;
    
    [self addChildViewController:vc.topViewController title:title imageName:imageName selectedImageName:selectedImageName];
}
// 利用vc创建控制器
- (void)addChildViewController:(UIViewController *)vc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName{
    vc.title = title;
//    vc.navigationItem.title = @"XU的微博";
//    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImageName];
    self.tabBar.tintColor = [UIColor orangeColor];
    [self addChildViewController:vc.navigationController];
    
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    UINavigationController *nav = (UINavigationController *)viewController;
    NSLog(@"%@控制器被点击了",nav.topViewController);
    if ([nav.topViewController isKindOfClass:[XUFirstController class]]) {
        XUFirstController *vc = [[XUFirstController alloc] init];
//        [vc updatewebo];
    
    }
}

@end
